#include "stdafx.h"
 
#include "qtoolbar.h"



using namespace micro::gui;


// standard toolbar styles
#define SIMPLE_TOOLBAR_STYLE \
	(WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS )
// toolbar in a rebar pane
#define SIMPLE_TOOLBAR_PANE_STYLE \
	(WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NODIVIDER | CCS_NORESIZE | CCS_NOPARENTALIGN | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT)



QToolBar::QToolBar(void)
{
  cx=cy=16;
}

QToolBar::~QToolBar(void)
{
}
void QToolBar::SetNotifyWindow(HWND hWnd)
{
		 
		SendMessage(TB_SETPARENT, (WPARAM)hWnd, 0L);
}

bool  QToolBar::Create(QWindow* parent)
{	 
	 
      bool bo = CreateBaseWindowEx(0,
      TOOLBARCLASSNAME,
      nullptr, 
	  SIMPLE_TOOLBAR_PANE_STYLE
      ,QRect(0,0,0,0), parent);	   
	  
	  SetStructSize();
	  return bo;
}
 
void QToolBar::AddButton(QButtonInfo &butInfo, bool showText, UINT style)
{
	TBBUTTON but={0}; 
	but.iBitmap = 0; 
	but.idCommand = butInfo.commandID; 
	but.fsState = TBSTATE_ENABLED; 
	but.fsStyle = style;  //BTNS_WHOLEDROPDOWN;//|TBSTYLE_DROPDOWN;      |BTNS_SEP
	but.dwData = 0; 
	but.iString = 0;


	if (showText)		  
	  but.iString = (INT_PTR)(LPCTSTR)butInfo.toolTip; 


	but.iBitmap = m_imageList.GetImageCount();
	HICON b = (HICON)::LoadImage( GetModuleHandle(0), 
		MAKEINTRESOURCE(butInfo.BitmapResID), IMAGE_ICON, cx,cy, LR_DEFAULTCOLOR	);


	if (! b) return;

	m_imageList.AddIcon(b);
	::DestroyIcon(b);


	AddButton(1, &but); 
}
